package com.zhima.enums;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.PrimitiveArrayUtil;
import com.baomidou.mybatisplus.annotation.EnumValue;

import java.util.Arrays;
import java.util.List;

public enum ScoreStrategy {
    /**
     * 计分策略
     */
    MAX("max") {
        @Override
        public int calculation(int[] scores) {
            return PrimitiveArrayUtil.max(scores);
        }

        @Override
        public int calculation(List<Integer> scores) {
            return ArrayUtil.max(scores.toArray(new Integer[0]));
        }
    },
    MIN("min") {
        @Override
        public int calculation(int[] scores) {
            return PrimitiveArrayUtil.min(scores);
        }

        @Override
        public int calculation(List<Integer> scores) {
            return ArrayUtil.min(scores.toArray(new Integer[0]));
        }
    },
    SUM("sum") {
        @Override
        public int calculation(int[] scores) {
            return Arrays.stream(scores).sum();
        }

        @Override
        public int calculation(List<Integer> scores) {
            return scores.stream().reduce(0, Integer::sum);
        }
    },
    SPJ("spj") {
        @Override
        public int calculation(int[] scores) {
            // 次方法作废
            return -1;
        }

        @Override
        public int calculation(List<Integer> scores) {
            // 此方法作废
            return -1;
        }
    },
    ;
    @EnumValue
    private final String strategy;

    ScoreStrategy(String strategy) {
        this.strategy = strategy;
    }

    public String getStrategy() {
        return strategy;
    }

    public abstract int calculation(int[] scores);

    public abstract int calculation(List<Integer> scores);
}
